// Created by liusc on 2020/9/17-9:24.
import {getDict} from "~/utils";
export default {
    name: "addition_look",
    data() {
        return {
            dialogVisible: false,
            isEdit: false,

            form: {
                applyTime: [],
                budgetId: '',
                budgetCode: '',
                applyName: '',
                applyDept: '',
                templateName: '',
                applyStart: '',
                applyEnd: '',
                remarks: '',
            },

            rules: {

            },

        }
    },

    mounted() {
    },

    created() {
        this.lists = getDict('budget_department');
    },

    methods: {
        daterangeChange(e){
            let _this =this
            _this.$nextTick(() => {
                _this.$set(_this.form, "applyTime", [e[0], e[1]]);
                _this.$forceUpdate();
            });
        },

        show(data) {
            const loading = this.$loading({
                lock: true,
                text: '数据处理中'
            });

            this.dialogVisible = true
            this.isEdit = true

            setTimeout(() => {
                this.$refs['edit-form'].resetFields()

                var scopeTime = [new Date(data.applyStart),new Date(data.applyEnd)]
                this.form=data
                this.form.applyTime=[]
                this.form.applyDept = data.applyDept.split(',')
                this.form.applyTime= scopeTime
                this.form.budgetId = data.budgetId;
                this.form.budgetCode = data.budgetCode;
                this.form.applyName = data.applyName;
                this.form.templateName = data.templateName;
                this.form.remarks = data.remarks;
                loading.close()
            }, 100)
        },

        dataFormat(value, fmt) {
            let getDate = new Date(value);
            let o = {
                'M+': getDate.getMonth() + 1,
                'd+': getDate.getDate(),
                'h+': getDate.getHours(),
                'm+': getDate.getMinutes(),
                's+': getDate.getSeconds(),
                'q+': Math.floor((getDate.getMonth() + 3) / 3),
                'S': getDate.getMilliseconds()
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
            }
            for (let k in o) {
                if (new RegExp('(' + k + ')').test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
                }
            }
            return fmt;
        },
    }
}
